<template>
  <div class="homepage fixt">
    <div class="delivery">
      <van-tabs v-model="active" :ellipsis="false" @click="onClicktab">
        <van-tab :title="item" :name="index+1" v-for="(item,index) in tabList" :key="index+'tabs'">
          <div v-if="listnul&&list.length===0&&pageInfo.page===1">暂无数据</div>
          <div>
            <van-list v-model="loading" :immediate-check="false" :finished="finished" @load="onLoad" :offset="10">
              <div class="zwlb">
                <!-- <van-cell v-for="item in list" :key="item" :title="item" /> -->
                <div class="zwlbdetails">
                  <ul>
                    <li v-for="(item,index) in list" :key='index'
                      @click="jobdetails(item.jobOutVo.id,item.jobOutVo.companyId,item.jobOutVo.category)">
                      <p class="zwlb">
                        {{item.jobOutVo.name}}
                        <span class="zwlbsj">{{item.jobOutVo.refreshTime}}</span>
                      </p>
                      <p>
                        {{item.jobOutVo.workAreaText===''?"地区不限":item.jobOutVo.workAreaText}}
                        <span class="zwfg">|</span>
                        {{item.jobOutVo.companyInfo?item.jobOutVo.companyInfo.name:""}}
                      </p>
                      <p>
                        <span>{{item.jobOutVo.minWage}}~{{item.jobOutVo.maxWage}}</span>
                        <span class="zwlbsj">{{item.statusText}}</span>
                      </p>
                    </li>
                  </ul>
                </div>
              </div>
            </van-list>
          </div>
        </van-tab>
      </van-tabs>
    </div>
  </div>
</template>
<script>
import POSITIONLIST from '@/api/PositionList'
// import timedate from '@/assets/js/datatime'
import { _debounce } from '@/assets/js/public'
export default {
  data () {
    return {
      zw: '',
      active: 1,
      loading: false,
      listnul: false,
      tabname: '',
      pageInfo: {
        page: 1,
        size: 10
      },
      tabList: ['全部', '被查看', '有意向', '邀面试', '不合适'], // tab数据
      list: [], // 全部数据
      finished: false
    }
  },
  computed: {},
  methods: {
    // 上拉加载
    onLoad: _debounce(function (_type, index, item) {
      let that = this
      console.log(that.pageInfo.page, 'that.pageInfo.page')

      that.loading = false

      that.pageInfo.page++
      that.deliverList(this.tabname)
    }, 2000),
    // tab切换
    onClicktab (name) {
      console.log(this.list.length, 'dsdsfdsf')
      let that = this
      this.list = []
      if (name === 1) {
        this.tabname = ''
      } else {
        this.tabname = name
      }

      this.pageInfo.page = 1
      this.finished = false
      this.listnul = false
      this.loading = true

      that.deliverList()

      console.log(name)
    },
    // 职位列表
    deliverList: _debounce(function (_type, index, item) {
      // do something ...
      // console.log(id, "id");
      let that = this
      let condition = [
        {
          column: 'status',
          type: 'eq',
          value: this.tabname
        },
        { column: 'include', type: '', value: 'D,CN' }
      ]
      let sort = [{ column: 'create_time', type: 'desc' }]
      var formData = new FormData()
      formData.append('page', this.pageInfo.page)
      formData.append('size', this.pageInfo.size)
      formData.append('condition', JSON.stringify(condition))
      formData.append('sort', JSON.stringify(sort))
      POSITIONLIST.deliverList(formData).then(res => {
        console.log(res.data)
        if (res.data.code === 200) {
          console.log(1)
          that.loading = false
          let numer = 0
          if (!res.data.data.records || res.data.data.records.length === 0) {
            // 加载结束
            that.finished = true
            that.listnul = true

            return
          } else {
            for (let i = 0; i < res.data.data.records.length; i++) {
              if (res.data.data.records[i].jobOutVo.id) {
                that.list.push(res.data.data.records[i])
              } else {
                numer++
              }
            }
            if (that.list.length === 0) {
              that.listnul = true
              that.finished = true
            }
          }

          // 如果列表数据条数>=总条数，不再触发滚动加载
          if (that.list.length >= res.data.data.total - numer) {
            that.finished = true
          }
        } else {
          that.list = []
        }
      })
    }, 600),

    // 详情跳转
    jobdetails (id, companyId, category) {
      this.$router.push({
        name: 'Jobdetails',
        query: {
          id: id,
          companyId: companyId,
          category: category
        }
      })
    }
  },
  created () {
    this.deliverList(1)
  }
}
</script>
<style scoped></style>
